package com.lanou.moving.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.moving.R;
import com.lanou.moving.entity.MusicInfo;
import com.lanou.moving.utils.Exchange;

import java.util.List;

/**
 * Created by 梁树珍 on 15/11/6.
 */
public class DownloadSingleAdapter extends BaseAdapter{
    private Context context;
    private List<MusicInfo> musicInfoList;

    public DownloadSingleAdapter(Context context, List<MusicInfo> musicInfoList) {
        this.context = context;
        this.musicInfoList = musicInfoList;
    }

    @Override
    public int getCount() {
        return musicInfoList == null ? 0 : musicInfoList.size();
    }

    @Override
    public Object getItem(int position) {
        return  musicInfoList == null ? null : musicInfoList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.songs_list_listview_item, null);
            holder = new ViewHolder();
            holder.songs_list_position = (TextView) convertView.findViewById(R.id.songs_list_position);
            holder.songs_list_songName = (TextView) convertView.findViewById(R.id.songs_list_songName);
            holder.songs_list_item_singer = (TextView) convertView.findViewById(R.id.songs_list_item_singer);
            holder.songs_list_item_number = (TextView) convertView.findViewById(R.id.songs_list_item_number);
            holder.list_more = (ImageView) convertView.findViewById(R.id.list_more);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.songs_list_position.setText(position + 1 + "");
        holder.songs_list_songName.setText(musicInfoList.get(position).getSongName());
        Log.i("songName", musicInfoList.get(position).getSongName());
        holder.songs_list_item_singer.setText(musicInfoList.get(position).getSingerName());
        holder.songs_list_item_number.setVisibility(View.GONE);
        return convertView;
    }
    private class ViewHolder {
        private ImageView list_more;
        private TextView songs_list_position;
        private TextView songs_list_songName;
        private TextView songs_list_item_singer;
        private TextView songs_list_item_number;

    }
}
